package com.example.yin.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Configuration
@Component
public class OSSConfiguration {

    private volatile static OSS ossClient;

    private volatile static OSSClientBuilder ossClientBuilder;

    private static String endpoint;

    private static String accessKeyId;

    private static String accessKeySecret;

    private  static  String fullUrl;

    private  static String songFilePath;

    private static String ArticlePicFilePath;

    private static String ShowPicFilePath;

    private  static String songListPicPath;

    private  static  String singerPicPath;

    private  static  String songPicPath;

    private  static  String avatorImagesPath;


    @Value("${aliyun.bucketName}")
    private String bucketName;

    public String getAvatorImagesPath() {
        return avatorImagesPath;
    }

    @Value("${aliyun.avatorImagesPath}")
    public void setAvatorImagesPath(String avatorImagesPath) {
        OSSConfiguration.avatorImagesPath = avatorImagesPath;
    }

    public String getSongPicPath() {
        return songPicPath;
    }

    @Value("${aliyun.songPicPath")
    public void setSongPicPath(String songPicPath) {
        OSSConfiguration.songPicPath = songPicPath;
    }

    public String getSingerPicPath() {
        return singerPicPath;
    }

    @Value("${aliyun.singerPicPath}")
    public void setSingerPicPath(String singerPicPath) {
        OSSConfiguration.singerPicPath = singerPicPath;
    }

    public String getSongListPicPath() {
        return songListPicPath;
    }

    @Value("${aliyun.songListPicPath}")
    public void setSongListPicPath(String songListPicPath) {
        OSSConfiguration.songListPicPath = songListPicPath;
    }

    public String getSongFilePath() {
        return songFilePath;
    }

    @Value("${aliyun.ArticlePicFilePath}")
    public void setArticlePicFilePath(String ArticlePicFilePath) {
        OSSConfiguration.ArticlePicFilePath = ArticlePicFilePath;
    }
    public String getArticlePicFilePath() {

        return ArticlePicFilePath;
    }

    @Value("${aliyun.songFilePath}")
    public void setSongFilePath(String songFilePath) {
        OSSConfiguration.songFilePath = songFilePath;
    }

    @Value("${aliyun.fullUrl}")
    private  void setfullUrl(String fullUrl){
        OSSConfiguration.fullUrl = fullUrl;
    }

    @Value("${aliyun.endpoint}")
    public void setEndpoint(String endpoint) {
        OSSConfiguration.endpoint = endpoint;
    }

    @Value("${aliyun.accessKeyId}")
    public void setAccessKeyId(String accessKeyId) {
        OSSConfiguration.accessKeyId = accessKeyId;
    }

    @Value("${aliyun.accessKeySecret}")
    public void setAccessKeySecret(String accessKeySecret) {
        OSSConfiguration.accessKeySecret = accessKeySecret;
    }

    public String getBucketName() {
        return bucketName;
    }

    public String getFullUrl(){
        return  fullUrl;
    }

    @Bean
    @Scope("prototype")
    public static OSS initOSSClient() {
        if (ossClient == null) {
            synchronized (OSSConfiguration.class) {
                if (ossClient == null) {
                    ossClient = initOSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
                }
            }
        }
        return ossClient;
    }

    public static OSSClientBuilder initOSSClientBuilder() {
        if (ossClientBuilder == null) {
            synchronized (OSSConfiguration.class) {
                if (ossClientBuilder == null) {
                    ossClientBuilder = new OSSClientBuilder();
                }
            }
        }
        return ossClientBuilder;
    }

    @Value("${aliyun.ShowPicFilePath}")
    public void setShowPicFilePath(String ShowPicFilePath) {
        OSSConfiguration.ShowPicFilePath = ShowPicFilePath;
    }
    public String getShowPicFilePath() {

        return ShowPicFilePath;
    }


//    @Value("${aliyun.ArticlePicFilePath}")
//    public void setArticlePicFilePath(String ArticlePicFilePath) {
//        OSSConfiguration.ArticlePicFilePath = ArticlePicFilePath;
//    }
//    public String getArticlePicFilePath() {
//
//        return ArticlePicFilePath;
//    }

}